<?php 
if(!empty($_POST['parents']))
{
	$parents=$_POST['parents'];
	$desc='';
	if($parents_ids=getIdsArr($parents))
	{
		$conn->query('select group_concat(title separator \'=&gt;\') as title from pages where id in('.implode(',',$parents_ids).') order by parents');	
		$row=$conn->fetch();
		if($row)
			$desc.=$row->title.'=&gt;';
	}
	$selected='';
	if(!empty($_POST['selected_catalogs']))
		$selected='p.id not in('.implode(',',$_POST['selected_catalogs']).') and';
	$par='';
	if($parents)
		$par='%'.$parents;
	$conn->query("select p.id, p.parents, p.title ,if((select p2.id from pages p2 where p2.parents=concat(p.parents,'#',p.id,'#') and p2.templ!='product' limit 1),0,1) as last from pages p where $selected p.templ!='product' and p.parents like '$par' ");
	if($conn->rowCount())
	{
		$ajax.='<ul class="to_select_list">';
		while($row=$conn->fetch())
			$ajax.='<li onclick="product_editor.'.($row->last?'addCatalog(\''.$desc.$row->title.'\','.$row->id.',this)" calss="last_catalog':'updateList(\''.$parents.'#'.$row->id.'#\',this)').'">'.$row->title.'</li>';		
	}
	else
	$ajax.='<div class="error">В выбранной категории нет конечных каталогов либо они все выбраны</div>';
}